home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / ubiquity / migration-assistant / ma-ask < prev    next >
Encoding:
Text File  |  2007-03-29  |  6.4 KB  |  202 lines

  1. #!/bin/sh
  2.  
  3. # TODO: Incorporate capb backup.
  4.  
  5. set -e
  6. . /usr/share/debconf/confmodule
  7. . /usr/share/migration-assistant/ma-script-utils
  8.  
  9.  
  10. if [ -z "$1" ]; then
  11.     mapath="/usr/bin"
  12. else
  13.     mapath="$1"
  14. fi
  15.  
  16. #FIXME: need a better solution.
  17. OLDIFS="$IFS"
  18. NEWLINE='
  19. '
  20. IFS="$NEWLINE"
  21. tmp=""
  22. for line in `os-prober`;
  23. do
  24.     dist=$(expr match "$line" '.*:\(.*\):.*:.*')
  25.     location=$(expr match "$line" '\(.*\):.*:.*:.*')
  26.     tmp="$tmp$dist ($location), "
  27. done
  28. tmp=${tmp%,*}
  29.  
  30. IFS="$OLDIFS"
  31.  
  32. db_subst migration-assistant/partitions choices "$tmp"
  33. db_input high migration-assistant/partitions || true
  34. db_go || exit 10
  35.  
  36. db_get migration-assistant/partitions
  37. IFS="$NEWLINE"
  38. selection=`echo "$RET" | sed -e 's/, /\n/g'`
  39. if [ -z "$selection" ]; then
  40.     exit
  41. fi
  42. for choice in $selection; # Microsoft Windows XP Professional (/dev/hda1)
  43. do
  44.     location=`expr "$choice" : '.*(\(.*\))$'` # /dev/hda1
  45.     for line in `os-prober`;
  46.     do
  47.     loc="${line%%:*}"
  48.     # make this not if continue, so we can save an indentation
  49.     if [ "$location" = "$loc" ]
  50.     then
  51.             log "setting ostype from: '$line'"
  52.             set_os_type "$line" || continue
  53.             log "got ostype of: '$ostype', mountpoint is: '$mountpoint'"
  54.  
  55.         path="${loc#*/*/}" # hda1 or discs/disc0/part1
  56.         IFS="$OLDIFS"
  57.         mount_os "$ostype" "$loc"
  58.         db_register migration-assistant/users migration-assistant/$path/users
  59.         db_subst migration-assistant/$path/users user-choices "$($mapath/ma-search-users "$ostype" "$mountpoint")"
  60.         db_subst migration-assistant/$path/users os-type "$choice"
  61.         
  62.  
  63.         db_input high migration-assistant/$path/users || true
  64.         db_go || exit 10
  65.  
  66.         db_get migration-assistant/$path/users
  67.         
  68.         user_selection=`echo "$RET" | sed -e 's/, /\n/g'`
  69.         IFS="$NEWLINE"
  70.         for usr in $user_selection;
  71.         do
  72.             IFS="$OLDIFS"
  73.         itemsret=$($mapath/ma-search-items --path="$mountpoint" --ostype="$ostype" --user="$usr") || \
  74.                     (itemsret=; error "ma-search-items exited with an error for $usr.")
  75.         formatted_user=`echo "$usr" | sed -e 's/ /:/g'`
  76.         db_register migration-assistant/items migration-assistant/$path/$formatted_user/items
  77.         db_subst migration-assistant/$path/$formatted_user/items choices "$itemsret"
  78.         db_subst migration-assistant/$path/$formatted_user/items user "$usr"
  79.  
  80.  
  81.         # migration-assistant/discs/disc0/part1/Evan/items
  82.         db_input high migration-assistant/$path/$formatted_user/items || true
  83.         db_go || exit 10
  84.         
  85.  
  86.         db_register migration-assistant/user migration-assistant/$path/$formatted_user/user
  87.         # This prevents m-a from working right. change to choices
  88.         #db_set migration-assistant/$path/$formatted_user/user "$(echo "$usr" | tr '[A-Z]' '[a-z]')"
  89.         db_subst migration-assistant/$path/$formatted_user/user old-user "$usr"
  90.  
  91.         while [ true ]; do
  92.             db_get migration-assistant/$path/$formatted_user/user || true
  93.             new_user="$RET"
  94.  
  95.             db_input high migration-assistant/$path/$formatted_user/user || true
  96.             db_go || exit 10
  97.             
  98.             db_get migration-assistant/$path/$formatted_user/user
  99.             if [ "$RET" = "skip-question" ]; then
  100.                 db_set migration-assistant/$path/$formatted_user/user "$new_user"
  101.                 break
  102.             fi
  103.  
  104.             new_user="$RET"
  105.             
  106.             if ! LC_ALL=C expr "$new_user" : '[a-z][-a-z0-9]*$' >/dev/null; then
  107.                 db_fset migration-assistant/$path/$formatted_user/user seen false
  108.                 db_fset migration-assistant/username-bad seen false
  109.                 db_subst migration-assistant/username-bad user "$new_user"
  110.                 db_input critical migration-assistant/username-bad
  111.                 continue
  112.             fi
  113.             
  114.             # TODO: Either copy this or depend on user-setup.
  115.             if grep -v '^#' /usr/lib/user-setup/reserved-usernames | \
  116.                grep -q "^$new_user\$"; then
  117.                 db_fset migration-assistant/$path/$formatted_user/user seen false
  118.                 db_fset migration-assistant/username-reserved seen false
  119.                 db_subst migration-assistant/username-reserved user "$new_user"
  120.                 db_input critical migration-assistant/username-reserved
  121.                 continue
  122.             fi
  123.             break
  124.         done
  125.  
  126.         # Only ask if the user doesn't match the one seeded for
  127.         # user-setup.
  128.         db_get passwd/username || true
  129.         if [ "$new_user" = "$RET" ]; then
  130.             continue
  131.         fi
  132.  
  133.         # Password
  134.         db_register migration-assistant/password migration-assistant/new-user/$new_user/password
  135.         db_subst migration-assistant/new-user/$new_user/password user "$new_user"
  136.  
  137.         db_register migration-assistant/password-again migration-assistant/new-user/$new_user/password-again
  138.         db_subst migration-assistant/new-user/$new_user/password-again user "$new_user"
  139.  
  140.         while [ true ]; do
  141.  
  142.             db_get migration-assistant/new-user/$new_user/password || true
  143.             pass=$RET
  144.             
  145.             db_input high migration-assistant/new-user/$new_user/password || true
  146.             db_go || exit 10
  147.             db_get migration-assistant/new-user/$new_user/password || true
  148.             
  149.             if [ "$RET" = "skip-question" ]; then
  150.                 db_set migration-assistant/new-user/$new_user/password "$pass"
  151.             break
  152.             fi
  153.             
  154.             pass=$RET
  155.  
  156.             db_input high migration-assistant/new-user/$new_user/password-again || true
  157.             db_go || exit 10
  158.             db_get migration-assistant/new-user/$new_user/password-again || true
  159.             pass2=$RET
  160.             
  161.             if [ -z "$pass2" ] || [ -z "$pass" ]; then
  162.                 db_set migration-assistant/new-user/$new_user/password ""
  163.                 db_set migration-assistant/new-user/$new_user/password-again ""
  164.                 db_fset migration-assistant/password-empty seen "false"
  165.                 db_input high migration-assistant/password-empty || true
  166.                 db_fset migration-assistant/new-user/$new_user/password seen "false"
  167.                 db_fset migration-assistant/new-user/$new_user/password-again seen "false"
  168.                 db_go || true
  169.                 
  170.             continue
  171.             fi
  172.  
  173.             if [ "$pass2" = "$pass" ]; then
  174.             break
  175.             else
  176.                 db_set migration-assistant/new-user/$new_user/password ""
  177.                 db_set migration-assistant/new-user/$new_user/password-again ""
  178.                 db_fset migration-assistant/password-mismatch seen "false"
  179.                 db_input high migration-assistant/password-mismatch || true
  180.                 db_fset migration-assistant/new-user/$new_user/password seen "false"
  181.                 db_fset migration-assistant/new-user/$new_user/password-again seen "false"
  182.                 db_go || true
  183.             fi
  184.  
  185.         done
  186.  
  187.         
  188.         # Full Name
  189.         db_register migration-assistant/fullname migration-assistant/new-user/$new_user/fullname
  190.         db_subst migration-assistant/new-user/$new_user/fullname user "$new_user"
  191.  
  192.         db_input high migration-assistant/new-user/$new_user/fullname || true
  193.         db_go || exit 10
  194.         
  195.         done
  196.         IFS="$NEWLINE"
  197.         unmount_os
  198.     fi
  199.     done
  200. done
  201. # vim:ai:et:sts=4:tw=80:sw=4:
  202.